package wechat.rcv.util;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;

import edu.fudan.mylang.pf.IObjectFactory;

@Controller
@Transactional
public class StaticController {
	final static Logger logger = Logger.getLogger(StaticController.class
			.getName());

	private IObjectFactory entities;

	@Autowired
	public StaticController(IObjectFactory entities) {
		this.entities = entities;
	}

//	@RequestMapping("/portrait/{engID}" + ".jpg")
//	@ResponseBody
//	public byte[] entryimage(@PathVariable String engID) {
//		try {
//			logger.info("pic id is " + engID);
//			BufferedImage img = ImageIO
//					.read(assertNotNull(
//							assertNotNull(
//									entities.get(Employee.class,
//											Long.parseLong(engID)), "engineer")
//									.getPortraitDoc(), "photo").getContent()
//							.getBinaryStream());
//			ByteArrayOutputStream bao = new ByteArrayOutputStream();
//			ImageIO.write(img, "jpg", bao);
//			return bao.toByteArray();
//		} catch (RuntimeException e) {
//			e.printStackTrace();
//			logger.error(e.getMessage());
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
//		return null;
//	}

	private <T> T assertNotNull(T t, String title) {

		if (t == null) {
			throw new RuntimeException(title + " is null");
		}
		return t;
	}
}